package com.zl.basis.log;

import android.util.Log;

import com.zl.basis.util.JsonUtil;

import java.util.HashMap;
import java.util.Map;

import timber.log.Timber;

public class TimberUtil {
    public static void i(String tag, String msg) {
        Timber.tag(tag);
        Timber.i(msg);
        Log.i(tag, msg);
    }

    public static void e(String tag, String msg) {
        Timber.tag(tag);
        Timber.e(msg);
        Log.e(tag, msg);
    }

    public static void d(String tag, String msg) {
        Timber.tag(tag);
        Timber.d(msg);
        Log.d(tag, msg);
    }

    public static void i(Map<String, Object> map) {
        Timber.i(new KeyValuesException(map));
    }

    public static void i(String[] keys, String[] values) {
        if (null != keys && null != values && keys.length == values.length) {
            Map<String, Object> map = new HashMap<>();
            for (int i = 0; i < keys.length; i++) {
                map.put(keys[i], values[i]);
            }
            Timber.i(new KeyValuesException(map));
        }
    }

    public static void i(String tag, Map<String, Object> map) {
        Log.i(tag, JsonUtil.toJson(map));
        Timber.i(new KeyValuesException(map));
    }

    public static void i(String tag, String[] keys, Object[] values) {
        if (null != keys && null != values && keys.length == values.length) {
            Map<String, Object> map = new HashMap<>();
            for (int i = 0; i < keys.length; i++) {
                map.put(keys[i], values[i]);
            }
            Log.i(tag, JsonUtil.toJson(map));
            Timber.i(new KeyValuesException(map));
        }
    }

    public static String getJsonLog(Map<String, String> map) {
        String json = "";
        if (map != null && map.size() > 0) {
            return JsonUtil.toJson(map);
        }
        return json;
    }

    public static String getJsonLog(String[] keys, Object[] values) {
        String json = "";
        if (null != keys && null != values && keys.length == values.length) {
            Map<String, Object> map = new HashMap<>();
            for (int i = 0; i < keys.length; i++) {
                map.put(keys[i], values[i]);
            }
            return JsonUtil.toJson(map);
        }
        return json;
    }

}
